package cn.initcap.designpattern.pattern.creational.singleton;

/**
 * @author initcap
 * @date 2018/8/28 AM9:09
 */
public class Runner implements Runnable {

    public static final int LAZYSINGLETON = 1;
    public static final int LAZYDOUBLECHECKSINGLETON = 2;
    public static final int STATICINNERCLASSSINGLETON = 3;
    public static final int CONTAINERSINGLETON = 4;
    public static final int THREADLOCALINSTANCE = 5;

    private int type;

    public Runner(int type) {
        this.type = type;
    }

    @Override
    public void run() {
        switch (type) {
            case LAZYSINGLETON:
                LazySingleton instance = LazySingleton.getInstance();
                System.out.println(Thread.currentThread().getName() + "  " + instance);
                break;
            case LAZYDOUBLECHECKSINGLETON:
                LazyDoubleCheckSingleton instance1 = LazyDoubleCheckSingleton.getInstance();
                System.out.println(Thread.currentThread().getName() + "  " + instance1);
                break;
            case STATICINNERCLASSSINGLETON:
                StaticInnerClassSingleton instance2 = StaticInnerClassSingleton.getInstance();
                System.out.println(Thread.currentThread().getName() + "  " + instance2);
                break;
            case CONTAINERSINGLETON:
                ContainerSingleton.putInstance("object", new Object());
                Object instance3 = ContainerSingleton.getInstance("object");
                System.out.println(Thread.currentThread().getName() + "  " + instance3);
                break;
            case THREADLOCALINSTANCE:
                ThreadLocalInstance instance4 = ThreadLocalInstance.getInstance();
                System.out.println(Thread.currentThread().getName() + "  " + instance4);
                break;
            default:
                EnumInstance instance5 = EnumInstance.getInstance();
                instance5.printTest();
                break;
        }

    }
}
